package com.scy.java.io.input;

import java.io.FileInputStream;
import java.io.IOException;

//读取字节数组存到缓冲区
public class FileInputStreamReads {
    public static void main(String[] args)  {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("d:/test.txt");

            //循环读取数据
            //定义变量记录每次读取的有效字节个数
            int len;
            //定义字节数组，保存字节数据
            byte[] b =new byte[3];
            //定义变量保存数据

            while ((len =fis.read(b)) != -1){
//                System.out.println(new String(b));
                System.out.println(new String(b,0,len));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    //关闭资源
                    fis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

    }
}
